home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group02b.txt / 000023_icon-group-sender_Tue Sep 10 07:49:26 2002.msg < prev    next >
Internet Message Format  |  2003-01-02  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id g8AEn4s10509
  4.     for icon-group-addresses; Tue, 10 Sep 2002 07:49:04 -0700 (MST)
  5. Message-Id: <200209101449.g8AEn4s10509@baskerville.CS.Arizona.EDU>
  6. X-Sender: whm@mail.mse.com
  7. Date: Mon, 09 Sep 2002 23:03:24 -0700
  8. To: Steve Graham <Steve_Graham@labcorp.com>
  9. From: "William H. Mitchell" <whm@mse.com>
  10. Subject: Re: Using Procedure Names for Debugging
  11. Cc: Icon Group <icon-group@cs.arizona.edu>
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14.  
  15. At 12:35 PM 9/9/02 -0500, Steve Graham wrote:
  16. >While developing an Icon program, I wanted an easy way to debug each
  17. >procedure.  I had read that there is more than 1 way to invoke a
  18. >command.  For example, you can have the statement write(5) or you can
  19. >have "write"(5).  I figured that I would use this idea to develop a test
  20. >module, to which I would pass a procedure name and arguments.  The test
  21. >module would in turn invoke the specified procedure as in the 2nd
  22. >example above with the arguments and report back the results, if any. 
  23. >However, I wasn't able to make it work.  I'd bet there is a way,
  24. >though.  Any ideas?
  25.  
  26. That approach sounds fine but there may be some detail tripping you up.
  27. One thing to note is that if you want to use string invocation (i.e.,
  28. "x"(1)), you need an "invocable" declaration if you're going to invoke
  29. non-builtins.
  30.  
  31. Here's a sample program that I think may do what you want:
  32.  
  33. invocable all  # declares all procedures as invocable
  34.  
  35. procedure main(args)
  36.     if r := args[1]!args[2:0] then  # calls procedure named as first
  37.                                     # command line argument with following 
  38.                                     # command line arguments
  39.         write("Result: ", image(r))
  40.     else
  41.         write("Call failed...")
  42. end
  43.  
  44. Here's a test procedure to use with it:
  45.  
  46. procedure x(y)
  47.     write("x called with ", y)
  48. end
  49.  
  50. Here are some examples of usage, assuming it's named "rp" (run procedure):
  51.  
  52. $ rp center abc 20 .
  53. Result: "........abc........."
  54.  
  55. $ rp find d "abcdefg"
  56. Result: 4
  57.  
  58. $ rp find x "abcdefg"
  59. Call failed...
  60.  
  61. $ rp x testing
  62. x called with testing
  63. Call failed...
  64.  
  65.  
  66. Note that the last invocation, "rp x testing" fails because there's no
  67. return or suspend at the end of x.  Note also that without the "invocable
  68. all" declaration, the last call would produce error 106.
  69.  
  70. Big picture-wise, however, you might find that qei, from the Icon Program
  71. Library is a general purpose tool for interactively evaluating Icon
  72. expressions:
  73.  
  74. $ qei
  75. Icon Expression Evaluator, Version 1.2, type :? for help
  76. > center("abc", 20, ".");
  77.    r1_ := "........abc........."  (string)
  78. > find("d", "abcdefg");
  79.    r2_ := 4  (integer)
  80. > find("x", "abcdefg");
  81. Failure
  82. >
  83.  
  84.  
  85.